﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
using System.Xml.Linq;

namespace PlistParser
{
    class PlistSerializer : XmlSerializer 
    {
        public object Deserialize(string path,string assemblyName)
        {
            MemoryStream stream = new MemoryStream();
            ReadPlist rp = new ReadPlist();
            rp.XMLparser(path);
            ConvertXML cx = new ConvertXML(rp.DateList);
            //Console.WriteLine(cx.creatXML());
            XDocument doc = cx.creatXML();
            doc.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            Type modelType = Type.GetType(assemblyName);
            XmlSerializer serializer = new XmlSerializer(modelType);

            try
            {
                object sender = serializer.Deserialize(stream);
                stream.Close();
                return sender;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                stream.Close();
                return null;
            }

        }
        

    }
}
